// ProjectTemplate.cpp: implementation of the ProjectTemplate class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ProjectTemplate.h"
#include "WndOperation.h"
#include "Application.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace PDMS
{
	namespace PDMSFrame
	{
		ProjectTemplate::ProjectTemplate()
		{
			
		}
		
		ProjectTemplate::~ProjectTemplate()
		{
			
		}
		
		UESoft::ErrorStatus ProjectTemplate::CreateProject( const StdString& strPrjPath,
											   const StdString& strPrjName )
		{
			CString strFilePath = strPrjPath;

			if( strPrjPath.GetAt(strPrjPath.GetLength()-1) != '\\' )
			{
				strFilePath += "\\" + strPrjName ;
			}
			else
			{
				strFilePath += strPrjName ;
			}
			if ( FileSystemOperation::IsPathFileExists( strFilePath ) )
			{
				return UESoft::eFileExists;
			}
			if( !FileSystemOperation::CreateDirectoryUE( strFilePath ) )
			{
				return UESoft::eFilerError;
			}

			//Copy system database
			::CopyFile( Application::Instance()->TemplatePath()+_T("DesignDBTemplate.mdb"),
				       (LPCSTR)( strFilePath + "\\" + "Design.mdb" ),
					   FALSE);
			::CopyFile( Application::Instance()->TemplatePath() + _T("SpecificationTemplate.mdb" ),
				       (LPCSTR)( strFilePath + "\\" + "Specification.mdb" ),
					   FALSE);
			

			//Create Project files
			strFilePath += "\\" + strPrjName + ".ueprj";			
			CFile file;
			file.Open(strFilePath,CFile::modeCreate|CFile::modeReadWrite);
			char* strText = "UEPDMS NO.1";
			file.Write(strText,11);
			file.Close();



			return UESoft::eOk;
		}
	}
}
